#pragma once

#include "Common.h"


struct SequenceList
{
	StudentInfo* data;
	const unsigned int capacity = 100;
	unsigned int size = 0;

	SequenceList()
	{
		// data = (StudentInfo*)malloc(sizeof(StudentInfo) * capacity);
		data = new StudentInfo[capacity];
	}

	SequenceList(const SequenceList& seqList) = delete;

	SequenceList& operator=(const SequenceList& another) = delete;

	~SequenceList()
	{
		delete[] data;
	}

	inline void CheckIndex(unsigned int index) const
	{
		if (index < 0 || index >= capacity) {
			throw std::exception("Invalid index for seq list.");
		}
	}

	inline void CheckCapacity() const
	{
		if (size > capacity) {
			throw std::exception("Seq list size > capacity.");
		}
	}

	void Set(unsigned int index, const StudentInfo& studentInfo)
	{
		CheckIndex(index);

		data[index] = studentInfo;
	}

	void Insert(unsigned int index, const StudentInfo& studentInfo)
	{
		CheckIndex(index);
		if (size >= capacity) {
			throw std::exception("Seq list size >= capacity.");
		}

		for (int i = capacity - 1; i > index; i--)
		{
			data[i] = data[i - 1];
		}

		Set(index, studentInfo);

		size++;
	}

	StudentInfo& Get(unsigned int index)
	{
		CheckIndex(index);

		return data[index];
	}

	const StudentInfo& Get(unsigned int index) const
	{
		CheckIndex(index);

		return data[index];
	}

	void Delete(unsigned int index)
	{
		CheckIndex(index);

		if (size <= 0)
		{
			throw std::exception("no elements to delete");
		}

		for (int i = index; i < capacity - 2; i++)
		{
			data[i] = data[i + 1];
		}

		size--;
	}

	void DeleteWhich(unsigned int which)
	{
		if (which < 1 || which > capacity) {
			throw std::exception("Invalid input.");
		}
		Delete(which - 1);
	}

	void PrintAll() const
	{
		for (int i = 0; i < capacity; i++)
		{
			Print(i);
		}
	}
	
	void Print(unsigned int index) const
	{
		CheckIndex(index);
		std::cout << Get(index) << std::endl;
		std::cout << "Addr: " << &Get(index) << std::endl;
	}

	void PrintWhich(unsigned int which) const
	{
		if (which < 1 || which > capacity) {
			throw std::exception("Invalid input.");
		}
		std::cout << Get(which - 1) << std::endl;
	}
};